import { createSlice } from "@reduxjs/toolkit";
// 创建一个reducer
const channelStore = createSlice({
    name: 'channelStore',
    initialState: {
        channels: []
    },
    reducers: {
        setChannels(state, action) {
            state.channels = action.payload
        }
    }
});
// 封装一个异步方法
function getChannels() {
    return async (dispatch) => {
        const response = await fetch('http://localhost:3000/channels');
        const data = await response.json();
        dispatch(channelStore.actions.setChannels(data));
    }
}
// 导出
export { getChannels }
export default channelStore.reducer;